/**
 * Created by Administrator on 2016/2/24.
 */
//导入request模块与crypto模块  *注解1

var request = require('./node_modules/request');
var crypto = require('crypto');

var zy = {
    config: {},
    set setConfig(config) {
        this.config = config;
    },
    sendSms: function(mobile, code, callback) {
        var timestamp = Math.round(new Date().getTime()/1000);
        var sign = crypto.createHash('md5').update(this.config.appKey + this.config.token
        + this.config.templateId + mobile + code + timestamp, 'utf8').digest("hex");
        var url = 'https://sms.zhiyan.net/sms/sms/single/' + this.config.appKey + '/' +
            this.config.token + '/' + this.config.templateId + '?timestamp=' + timestamp + '&sign=' + sign;
        var data = JSON.stringify({
            mobile: mobile,
            param: code,
            extend: ''
        });
        var opt = {
            rejectUnauthorized: false,
            url: url,
            method: 'POST',
            form: {
                data: data
            }
        };
        request(opt, callback);
    }
};
module.exports = zy;



